package com.koron.css2.serviceManage.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.CodeRuleBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.CodeRuleMapper;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import com.koron.util.Tools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 编码规则添加
 * @author 周新宇
 *
 */
public class CodeRuleAdd implements ServerInterface {

	private static Logger logger = LogManager.getLogger(CodeRuleAdd.class);
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		CodeRuleMapper mapper = factory.getMapper(CodeRuleMapper.class);
		try {
			CodeRuleBean bean = JsonUtils.objectToPojo(req.getData(), CodeRuleBean.class);
			bean.setCreateAccount(userInfo.getUserInfo().getAcount());
			bean.setCreateName(userInfo.getUserInfo().getName());
			bean.setCreateTime(CommonUtils.getCurrentTime());
			bean.setId(Tools.getObjectId());
			mapper.saveCodeRule(bean);
		} catch (Exception e) {
			logger.error("非法参数",e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "执行失败", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}

}
